from web_api import *
from model import *
'''
provides ui interfaces for the application
'''

ws = webServer()
template = templateFactory()

class meetingBase(object):
    '''
    Base class for other meeting methods
    '''

    def __init__(self):
        '''
        Log user information
        '''
        ws.log('did this happen first??? ')
       
    """
    @cherrypy.expose
    def createEvent(self, ):
        '''
        Create a new event in the database...
        '''
        
        userID = ws.getSessionValue('UID')
        
    """    
    
    @cherrypy.expose
    def doLogout(self):
        '''
        Clear session
        Logout user
        '''
        ws.logout()
        
    @cherrypy.expose
    def createEvent(self, **FormData ):
        '''
        Handler for schedule.html form -> createEventForm
        '''
        FormData['HOST_ID'] = ws.getSessionValue('UID')
        
        print "Got this -> %s" %(FormData)
        cc = calendarControl()
        cc.addEvent(FormData)
        ws.redirect()
        
        
    @cherrypy.expose
    def createRoom(self, **FormData ):
        '''
        Handler for admin_rooms.html form -> createNewRoomForm
        '''
        rc = roomControl()
        rc.addRoom(FormData)     
        ws.redirect()
        
class adminControls:
    '''
    Admin specifc features
    Has CRUD rights for:
    1.) Rooms
    2.) Users
    '''
        
   
    

class webServices(meetingBase):
    '''
    Web services for application
    '''
    
    @cherrypy.expose
    def getRoomData(self):
        '''
        Accessable via /ws/getRoomData
        '''
        '''
        #Tests 
        jsonTest = """ [{"roomName": "RoomA", "roomID": 1, "roomSize": 10}, {"roomName": "RoomB", "roomID": 2, "roomSize": 3}, {"roomName": "RoomC", "roomID": 3, "roomSize": 20}, {"roomName": "RoomD", "roomID": 4, "roomSize": 15}, {"roomName": "RoomE", "roomID": 5, "roomSize": 8}] """
        return jsonTest
        '''
        rc = roomControl()
        rooms = rc.getWsRoomList()
        return rooms
    
    @cherrypy.expose
    def getUserData(self):
        '''
        Accessable via /ws/getUserData
        '''
        rc = userControl()
        users = rc.getWsAllUsers()
        return users 
    
    
    @cherrypy.expose
    def getEventData(self, start, end, _):
        '''
        Accessable via /ws/getUserData
        '''
        cc = calendarControl()
        events = cc.getWsEventList(ws.getSessionValue('UID'))
        return events
    @cherrypy.expose
    def getAllEventData(self):
        '''
        Accessable via /ws/getUserData
        '''
        cc = calendarControl()
        events = cc.getWsEventList(ws.getSessionValue('UID'))
        return events


class meetingController(meetingBase):
    
    
    def __init__(self):
        '''
        Load additional web parts into the controller view
        '''
        
        self.ws =  webServices()
        
        
        
    
    
    @cherrypy.expose
    def index(self):
        '''
        This is the main page...
        '''
        info = {}
        data = {}
        
        timeout = cherrypy.session
        info['addr'] = cherrypy.request.remote.ip
        info['port'] = cherrypy.request.remote.port
        info['host'] = cherrypy.request.remote.name
        
        '''
        Get full name set during login...
        '''
        
        userFullName = ws.getSessionValue('FullName')
        adminCheck = ws.getSessionValue('isAdmin')
        
        
        
        
        print "Dump session values...."
        for (k,v) in ws.dumpSession():
            print "%s = %s" %(k, v)
        data = {'sess_fullname': userFullName, 'sess_admin': adminCheck, 'name': 'State_Your_Name', 'to': timeout, 'data': [{'this': 'a', 'that': '1'}, {'this': 'b', 'that': '2'},{'this': 'c', 'that': '3'} ] }
        return  template.render('main.html', data)
    
       






